<!DOCTYPE html>
<html lang="zh">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>学习助手</title>
    <link rel="stylesheet" type="text/css" href="./static/bootstrap/css/bootstrap.min.css">

    <link rel="stylesheet" type="text/css" href="./static/css/style.css">
    <link rel="icon" href="./static/img/logo.png" type="image/png">
</head>
<style>
    .title_label {
        left: 18px;
        top: 0px;
        height: 29px;
        color: rgba(255, 255, 255, 1);
        font-size: 20px;
        text-align: left;
        font-family: PingFangSC-bold;
    }

    .header_main {
        width: 100%;
        margin: auto;
        background-image: url(/static/img/head_bg.png);
        background-position: top -140px right 0px;
        height: auto;
        padding: 10px;
        background-size: cover;
        background-size: 100%;
        background-repeat: no-repeat;
        color: dimgray;

    }


    .menuStyle>li {
        float: left;
        margin-left: 10px;
        color: #0e5407;
        font-size: 16px;
        font-weight: 700;
    }

    .workStyle>li {
        float: left;
        margin-left: 10px;
        color: #fff;
        font-weight: 700;
    }

    #infoDiv {
        margin-top: 50px;
        font-size: medium;
    }

    #infoDiv>label {
        margin-top: 10px;
    }

    .inputForm>label {
        margin-top: 20px;
    }
</style>

<body id="mainAPP" class="header_main">
    <header id="home">

        <ul class="workStyle">
            <li>
                <!-- 今日，参数是当前时间往后退1天，所以参数天1 -->
                <button class="btn btn-success" onclick="window.location.href='/home'">个人信息 </button>

            </li>
            <li>
                <!-- 今日，参数是当前时间往后退1天，所以参数天1 -->
                <button class="btn btn-warning" onclick="window.location.href='/records'">加分记录 </button>

            </li>
            <li>
                <!-- 7天，参数是当前时间往后退7天，所以参数填7 -->
                <button class="btn btn-secondary" onclick="window.location.href='/fill'">填写加分 </button>
            </li>

        </ul>

    </header>
    <!-- 为 图表设置的 DOM -->
    <!-- 列出所选日期内有工作量的设备 -->


    <form id="infoDiv">

    </form>
    <div class="container" style="position: fixed; bottom: 50px;">
        <div class="row">
            <div class=" col-4">
                <button class="btn-sm btn-warning" data-bs-toggle="modal" data-bs-target="#pswdModal"> 修改密码 </button>
            </div>
            <div class=" col-4">
                <button class="btn-sm btn-success" data-bs-toggle="modal" data-bs-target="#infoModal"> 修改资料 </button>
            </div>
            <div class=" col-4">
                <button class="btn-sm btn-primary" onclick="canyuchoujiaing()" > 参与抽奖 </button>
            </div>
        </div>
    </div>

    <div class="modal" id="pswdModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">修改密码</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <form class="modal-body inputForm">
                    <label for="oldPswdInput">原来密码:</label>
                    <input type="password" id="oldPswdInput"> <br>
                    <label for="newPswdInput">新的密码:</label>
                    <input type="password" id="newPswdInput"><br>
                    <label for="rePswdInput">确认密码:</label>
                    <input type="password" id="rePswdInput">
                </form>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" onclick="savePswd() "
                        data-bs-dismiss="modal">确定修改</button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal" id="infoModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">修改资料</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <form class="modal-body inputForm">
                    <label for="telInput">电话:</label>
                    <input id="telInput"> <br>
                    <label for="emailInput">邮箱:</label>
                    <input id="emailInput" placeholder="0000000@qq.com"><br>
                    <label for="commentsInput">备注:</label>
                    <input id="commentsInput">
                </form>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" onclick="saveInfo() "
                        data-bs-dismiss="modal">确定修改</button>
                </div>
            </div>
        </div>
    </div>
    <div style="position:absolute; bottom: 0px;left: 0; width: 100%;   background-color: #17ad74; " id="bottomBox">
        <div style="color: white; text-align: center;" id="userinfo">信息工程学院</div>
    </div>
    <script type="text/javascript" src="./static/js/md5.js"></script>
    <script src="./static/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="./static/js/axios.min.js"></script>
    <script type="text/javascript">
        // 选择设备后，跳转到
        let info;
        function fillInfo() {
            let infoStr = sessionStorage.getItem("user");
            info = JSON.parse(infoStr);
            let infoDiv = ` 
   <br/> <label  >姓名:</label>`+ info.Name + `
    <label style='margin-left:20px' >性别:</label>`+ info.Sex + `
    <label style='margin-left:10px' >学籍:</label>`+ info.Xueji + `
   <br/>   <label >学号:</label>`+ info.Sn + `
   <br/>   <label  >密码:</label>`+ info.PSWD + `
   <br/>    <label >班级:</label>`+ info.Classname + `
   <br/>    <label >邮箱:</label>`+ info.Email + ` 
   <br/>    <label >电话:</label>`+ info.Tel + ` 
   <br/>    <label >云主机1:</label>`+ info.IP1 + `
   <br/>   <label >云主机2:</label>`+ info.IP2 + `
   <br/>   <label >云主机3:</label>`+ info.IP3 + `
   <br/>   <label >备注:</label><text  >`+ info.Comments + ` </text>  `;
            document.getElementById("infoDiv").innerHTML = infoDiv;
            document.getElementById("userinfo").innerText = info.Classname + "." + info.Name;
            // 填充修改资料
            document.getElementById("telInput").value = info.Tel;
            document.getElementById("emailInput").value = info.Email;
            document.getElementById("commentsInput").value = info.Comments;
        }
        fillInfo();
        function savePswd() {
            let infoStr = sessionStorage.getItem("user");
            info = JSON.parse(infoStr);
            if (md5(document.getElementById("oldPswdInput").value) != info.PSWD) {
                alert("原来的密码不对");
                return
            }
            let newPswd = document.getElementById("newPswdInput").value;

            if (newPswd != document.getElementById("rePswdInput").value) {
                alert("两次输入的密码不一致");
                return
            }
            newPswd = md5(newPswd);
            var jwt = sessionStorage.getItem("token");
            axios.put('/api/classmates/pswd/' + newPswd, {}, { headers: { 'token': jwt } }).then(function (response) {
                // 判断返回的数据是否正常 
                if (response.data.code == 0) {

                    alert(response.data.data);
                    return
                }
                sessionStorage.setItem("user", JSON.stringify(response.data.data));
                fillInfo();

            }).catch(function (error) {
                alert(error)
            });
        }
        function saveInfo() {
            let infoStr = sessionStorage.getItem("user");
            info = JSON.parse(infoStr);
            info.Tel = document.getElementById("telInput").value;
            info.Email = document.getElementById("emailInput").value;
            info.Comments = document.getElementById("commentsInput").value;
            var jwt = sessionStorage.getItem("token");
            axios.put('/api/classmates/updateInfo/mine', info, { headers: { 'token': jwt } }).then(function (response) {
                // 判断返回的数据是否正常
                if (response.data.code == 0) {
                    alert(response.data.data);
                    return
                }
                sessionStorage.setItem("user", JSON.stringify(response.data.data));
                fillInfo();
            }).catch(function (error) {
                alert(error)
            });
        }
        function canyuchoujiaing() {
            var jwt = sessionStorage.getItem("token");
            axios.get('/api/records/canyuChoujiang',  { headers: { 'token': jwt } }).then(function (response) {
                // 判断返回的数据是否正常
                if (response.data.code == 0) {
                    alert(response.data.data);
                    return
                }else{
                    alert(response.data.name+"报名抽奖成功");
                }
 
            }).catch(function (error) {
                alert(error)
            });
        }

    </script>

</body>

</html>